package com.hzhjhh.view.manageView.menus.accountMng;


import javax.swing.*;

import com.hzhjhh.means.DelData;
import com.hzhjhh.means.GetTime;
import com.hzhjhh.means.Insert_stock;
import com.hzhjhh.means.Select_Means;
import com.hzhjhh.means.UpdateData;
import com.hzhjhh.util.TimerScheduleTaskUtil;
import com.hzhjhh.view.manageView.menus.accountMng.register.CardId;
import com.hzhjhh.view.manageView.menus.accountMng.register.CardOpenDate;
import com.hzhjhh.view.manageView.menus.accountMng.register.CardOwner;
import com.hzhjhh.view.manageView.menus.accountMng.register.DeleteBt;
import com.hzhjhh.view.manageView.menus.accountMng.register.Discount;
import com.hzhjhh.view.manageView.menus.accountMng.register.IDCard;
import com.hzhjhh.view.manageView.menus.accountMng.register.Password;
import com.hzhjhh.view.manageView.menus.accountMng.register.QueryBt;
import com.hzhjhh.view.manageView.menus.accountMng.register.QuitBt;
import com.hzhjhh.view.manageView.menus.accountMng.register.RegisterBt;
import com.hzhjhh.view.manageView.menus.accountMng.register.Remark;
import com.hzhjhh.view.manageView.menus.accountMng.register.Score;
import com.hzhjhh.view.manageView.menus.accountMng.register.Term;
import com.hzhjhh.view.manageView.menus.accountMng.register.UpdateBt;
import com.hzhjhh.view.manageView.menus.accountMng.register.UserType;

import lombok.Getter;
import lombok.Setter;

import java.awt.*;
import java.util.Vector;

/**
 * 后台用户注册对话框
 * 
 * @author 12083
 *
 */
@Getter
@Setter
public class RegisterDialog extends JDialog {
    JPanel panel1 = new JPanel();
    JTextField txfCardId = new JTextField();
    JTextField txfCardOwner = new JTextField();
    JTextField txfIDCard = new JTextField();
    JTextField txfDiscount = new JTextField();
    JLabel lbCardId = new JLabel();
    JLabel lbCardOwner = new JLabel();
    JLabel lbIDCard = new JLabel();
    JLabel lbPassword = new JLabel();
    JLabel lbDiscount = new JLabel();
    JTextField txfTerm = new JTextField();
    JTextField txfScore = new JTextField();
    JTextArea txaRemark = Remark.txaInit();
    JLabel lbUserType = new JLabel();
    JLabel lbTerm = new JLabel();
    JLabel lbScore = new JLabel();
    JTextField txfCardOpenDate = new JTextField();
    JLabel lbCardOpenDate = new JLabel();
    JLabel lbRemark = new JLabel();
    JScrollPane jScrollPane1 = new JScrollPane();
    JButton btRegister = new JButton();
    JButton btQuitBt = new JButton();
    JComboBox cobUserType = new JComboBox();
    JButton btUpdate = new JButton();
    JButton btDelete = new JButton();
    JButton btQuery = new JButton();
    JPasswordField passwordField = Password.psInit();
    public RegisterDialog(Frame owner, String title, boolean modal) {
        super(owner, title, modal);
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
            pack();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public RegisterDialog() {
        this(new Frame(), "注册用户", false);
        this.setSize(500, 400);
        this.setLocation(300, 200);
    }

    private void jbInit() throws Exception {

        panel1.setLayout(null);
        txfCardId = CardId.txfInit();
        txfCardOwner = CardOwner.txfInit();
        txfIDCard = IDCard.txfInit();
        txfDiscount = Discount.txfInit();
        lbCardId = CardId.btInit();
        lbCardOwner = CardOwner.btInit();
        lbIDCard = IDCard.btInit();
        lbPassword = Password.btInit();
        lbDiscount = Discount.btInit();
        txfTerm = Term.txfInit();
        txfScore = Score.txfInit();
        lbUserType = UserType.btInit();
        lbTerm = Term.btInit();
        lbScore = Score.btInit();
        txfCardOpenDate = CardOpenDate.txfInit();
//        txfCardOpenDate.setBounds(new Rectangle(109, 209, 132, 27));
//        txfCardOpenDate.setText(GetTime.getTime());
        lbCardOpenDate = CardOpenDate.btInit();
//        lbCardOpenDate.setBounds(new Rectangle(51, 214, 61, 15));
        lbRemark = Remark.btInit();
        jScrollPane1.setBounds(new Rectangle(308, 210, 105, 82));
        btRegister = RegisterBt.btInit(this);
//        btRegister.addActionListener(event -> {
//        	String cardId = txfCardId.getText(); //卡号
//            String name = txfCardOwner.getText(); //持卡人
//            String IDcard = txfIDCard.getText(); //身份证
//            String password = passwordField.getText(); //密码
//            String CardDate = txfCardOpenDate.getText(); //开卡日期
//            String UserGrade = cobUserType.getSelectedItem().toString(); //用户类型
//            String term = txfTerm.getText(); //期限
//            String integral = txfScore.getText(); //积分
//            String agio = txfDiscount.getText(); //折扣
//            String remark = txaRemark.getText();
//    		int i = Insert_stock.Insert_User(cardId, name, IDcard, password,
//                    CardDate,
//                    UserGrade, term, integral, agio,
//                    remark);
//            if (i != 0) {
//                JOptionPane.showMessageDialog(this, "开卡成功", "提示",
//                        JOptionPane.INFORMATION_MESSAGE);
//            } else {
//                JOptionPane.showMessageDialog(this, "开卡失败", "提示",
//                        JOptionPane.INFORMATION_MESSAGE);
//                return;
//            }
//        });
        btQuitBt = QuitBt.btInit(this);
        panel1.setBackground(Color.pink);
        cobUserType = UserType.cobInit();
//        TimerScheduleTaskUtil.time2Show(txfCardOpenDate);
//        cobUserType.addItem("普通会员");
//        cobUserType.addItem("收银员");
//        cobUserType.addItem("管理员");
        btUpdate = UpdateBt.btInit(this);
//        btUpdate.setText("修改");
//        btUpdate.addActionListener(event -> {
//        	String cardId = txfCardId.getText(); //卡号
//            Vector Select_vector = new Vector();
//            Select_vector = Select_Means.Select_UserManager(cardId); //查询此卡是否存在
//            if (Select_vector.size() == 0) {
//                JOptionPane.showMessageDialog(this, "卡号不存在", "提示",
//                        JOptionPane.INFORMATION_MESSAGE);
//                return;
//            }
//            int i = UpdateData.UpdateCard(txfCardId.getText(),txfCardOwner.getText(),
//                    txfIDCard.getText(),
//                    passwordField.getText(),
//                    txfCardOpenDate.getText(),
//                    cobUserType.getSelectedItem().toString(),
//                    txfTerm.getText(),
//                    txfScore.getText(),
//                    txfDiscount.getText(), txaRemark.getText()
//            );
//            if (i == 0) {
//                JOptionPane.showMessageDialog(this, "资料更新失败", "提示",
//                        JOptionPane.INFORMATION_MESSAGE);
//            } else {
//                JOptionPane.showMessageDialog(this, "资料更新成功", "提示",
//                        JOptionPane.INFORMATION_MESSAGE);
//            }
//        });
        btDelete = DeleteBt.btInit(this);
//        btDelete.setText("删除用户");
//        btDelete.addActionListener(event -> {
//        	int i=0;
//            i= DelData.delCard(txfCardId.getText());
//            if (i != 0) {
//                JOptionPane.showMessageDialog(this, "删除成功", "提示",
//                        JOptionPane.INFORMATION_MESSAGE);
//            } else {
//                JOptionPane.showMessageDialog(this, "删除失败", "提示",
//                        JOptionPane.INFORMATION_MESSAGE);
//                return;
//            }
//        });
        btQuery = QueryBt.btInit(this);
//        btQuery.setText("查询");
//        btQuery.addActionListener(event -> {
//        	String cardId = txfCardId.getText(); //卡号
//            Vector Select_vector = new Vector();
//            Select_vector = Select_Means.Select_UserManager(cardId); //查询此卡是否存在
//            if (Select_vector.size() == 0) {
//                JOptionPane.showMessageDialog(this, "卡号不存在", "提示",
//                        JOptionPane.INFORMATION_MESSAGE);
//                return;
//            }
//
//            txfCardId.setText(Select_vector.get(0).toString()); //卡号
//            txfCardOwner.setText(Select_vector.get(1).toString()); //持卡人
//            txfIDCard.setText(Select_vector.get(2).toString()); //身份证
//            txfCardOpenDate.setText(Select_vector.get(4).toString()); //开卡日期
//            if (Select_vector.get(5).toString().equals("普通会员")) {
//                cobUserType.removeAllItems();
//                cobUserType.addItem("普通会员");
//                cobUserType.addItem("收银员");
//                cobUserType.addItem("管理员");
//            }
//            if (Select_vector.get(5).toString().equals("收银员")) {
//                cobUserType.removeAllItems();
//                cobUserType.addItem("收银员");
//                cobUserType.addItem("普通会员");
//                cobUserType.addItem("管理员");
//            }
//            if (Select_vector.get(5).toString().equals("管理员")) {
//                cobUserType.removeAllItems();
//                cobUserType.addItem("管理员");
//                cobUserType.addItem("收银员");
//                cobUserType.addItem("普通会员");
//            }
//            txfTerm.setText(Select_vector.get(6).toString()); //期限
//            txfScore.setText(Select_vector.get(7).toString()); //积分
//            txfDiscount.setText(Select_vector.get(8).toString()); //折扣
//            txaRemark.setText(Select_vector.get(9).toString()); //备注
//        });
////        jPasswordField1.setBounds(new Rectangle(109, 169, 132, 27));
        panel1.add(txfIDCard);
        panel1.add(txfCardOwner);
        panel1.add(lbCardId);
        panel1.add(lbCardOwner);
        panel1.add(lbIDCard);
        panel1.add(lbPassword);
        panel1.add(lbTerm);
        panel1.add(lbScore);
        panel1.add(lbRemark);
        panel1.add(lbUserType);
        panel1.add(txfTerm);
        panel1.add(txfScore);
        panel1.add(jScrollPane1);
        panel1.add(btRegister);
        panel1.add(cobUserType);
        panel1.add(btUpdate);
        panel1.add(btQuitBt);
        panel1.add(btDelete);
        panel1.add(btQuery);
        panel1.add(txfDiscount);
        panel1.add(lbDiscount);
        panel1.add(txfCardOpenDate);
        panel1.add(lbCardOpenDate);
        panel1.add(txfCardId);
        panel1.add(passwordField);
        jScrollPane1.getViewport().add(txaRemark);
        this.getContentPane().add(panel1, java.awt.BorderLayout.CENTER);
    }
}





